<?php 
namespace app\wx\controller;

use think\Exception;
use think\Controller;

use app\wx\model\Favor as FavorModel;
class Favor extends Controller { 
  public function addFavor() {
    $favor = new FavorModel();
    $favor->user = $this->request->param('user');
    $favor->favor_id = $this->request->param('id');
    $favor->type = $this->request->param('type');
    $data = $favor->save();
    if($data) {
        return json([
            "msg"=> "success",
            "code"=>20000
        ],200);
    }
  }

  public function cancelFavor() {
    $favor = new FavorModel();
    $data = $favor::where("user", $this->request->param('user'))->where("favor_id", $this->request->param('id'))->where("type", $this->request->param('type'))->delete();
    if($data) {
      return json([
          "msg"=> "success",
          "code"=>20000
      ],200);
    }
  }

  public function getBookFavorNum() {
    $favor = new FavorModel();
    $data = $favor::where("user", $this->request->param('user'))->where("type", 400)->select()->count();
    if($data) {
      return json([
          "msg"=> "success",
          "data"=> $data,
          "code"=>20000
      ],200);
    }
  }
}